home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_06
/
8n06089a
< prev
next >
Wrap
Text File
|
1990-04-18
|
2KB
|
118 lines
*****Listing 2*****
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "fgiproto.h"
#define FGL_BUFSIZE 256
/* 4GL syntax is CALL OpenAsciiFile(filename,mode) returning filehandle */
fgl_fopen(nargs)
int nargs;
{
char filename[80];
char mode[10];
FILE *ascfile;
popquote(mode,sizeof(mode)-1);
popquote(filename,sizeof(filename)-1);
clipped(mode);
clipped(filename);
ascfile = fopen(filename,mode);
retlong((long)ascfile);
return 1;
}
/* 4GL syntax is CALL fgl_fclose(filehandle) */
fgl_fclose(nargs)
int nargs;
{
long filehandle;
poplong(&filehandle);
fclose((FILE *)filehandle);
return 0;
}
/* 4GL syntax is
CALL fgl_fgets(filehandle) returning err_code, buffer */
fgl_fgets(nargs)
int nargs;
{
long filehandle;
char buffer[FGL_BUFSIZE];
short err_code=0;
int len;
poplong(&filehandle);
memset(buffer,0,sizeof(buffer));
if (fgets(buffer, sizeof(buffer)-1, (FILE *)filehandle) != NULL) {
len = strlen(buffer);
buffer[len-1] = '\0'; /* trim \r */
}
else
err_code = -1;
retshort(err_code);
retquote(buffer);
return 2;
}
/* 4GL syntax is
CALL fgl_fputs(buffer,filehandle) returning err_code */
fgl_fputs(nargs)
int nargs;
{
long filehandle;
char buffer[FGL_BUFSIZE];
short err_code=0;
int len;
poplong(&filehandle);
popquote(buffer,sizeof(buffer)-1);
clipped(buffer,(char)' ');
err_code = fputs(buffer,(FILE *)filehandle);
fputc('\n',(FILE *)filehandle);
retshort(err_code);
return 1;
}
/* 4GL syntax is
CALL fgl_max(arg1, arg2, ...) returning max_val */
fgl_max(nargs)
int nargs;
{
int i;
short test_val;
short max_val = -32767;
for (i=0; i<nargs; i++) {
popshort(&test_val);
if (test_val > max_val)
max_val = test_val;
}
retshort(max_val);
return 1;
}
clipped(str) /* trim trailing blanks */
char *str;
{
char *blank;
blank = str + strlen(str) - 1;
while (*blank == ' ')
*blank-- = '\0';
}